/**
 * 管理初始化
 */
var TDApply = {
    id: "TDApplyTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
TDApply.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '创建人姓名', field: 'name', visible: true, align: 'center', valign: 'middle'},
            {title: '创建人登录名', field: 'login_name', visible: true, align: 'center', valign: 'middle'},
            {title: '创建日期', field: 'createtime', visible: true, align: 'center', valign: 'middle'},
            {title: '申请名称', field: 'apply_name', visible: true, align: 'center', valign: 'middle'},
            {title: '申请编号', field: 'apply_serial', visible: true, align: 'center', valign: 'middle'},
            {title: '单位数', field: 'count', visible: true, align: 'center', valign: 'middle'},
            {title: '钱数', field: 'money', visible: true, align: 'center', valign: 'middle'},
            {title: '申请类型', field: 'type', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
TDApply.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        TDApply.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加
 */
TDApply.openAddTDApply = function () {
    var index = layer.open({
        type: 2,
        title: '添加',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/tDApply_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看详情
 */
TDApply.openTDApplyDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/tDApply_update/' + TDApply.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除
 */
TDApply.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/delete", function (data) {
            Feng.success("删除成功!");
            TDApply.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("tDApplyId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询列表
 */
TDApply.search = function () {
    var queryData = {};
    queryData['applyName'] = $("#applyName").val();
    queryData['applySerial'] = $("#applySerial").val();
    queryData['count'] = $("#count").val();
    queryData['money'] = $("#money").val();
    queryData['type'] = $("#type").val();
    TDApply.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = TDApply.initColumn();
    var table = new BSTable(TDApply.id, "/getPageList", defaultColunms);
    table.setPaginationType("server");
    TDApply.table = table.init();
});
